package com.sz.app.edi.exception;

import com.sz.common.base.exception.ErrorCode;
import com.sz.common.base.i18n.I18nMessageHelper;

/**
 * Function: Exceptions <br>
 * Author: Charles <br>
 * Date: 2016-12-14 09:58:00
 */
public class EdiExceptions {
    /**
     * @param code
     * @return
     */
    public static EdiException ediException(ErrorCode code) {
        return ediException(code, new String[]{});
    }

    /**
     * @param errorCode
     * @param args
     * @return
     */
    public static EdiException ediException(ErrorCode errorCode, String... args) {
        String[] iArgs = (args != null && args.length > 0) ? args : errorCode.getDefaultArguments();
        String message = I18nMessageHelper.getI18nMessage(errorCode.getMessageKey(), iArgs);
        return new EdiException(errorCode.getCode(), message);
    }

    public static EdiException ediExceptionData(ErrorCode errorCode, Object data, String... args) {
        String[] iArgs = (args != null && args.length > 0) ? args : errorCode.getDefaultArguments();
        String message = I18nMessageHelper.getI18nMessage(errorCode.getMessageKey(), iArgs);
        EdiException exception = new EdiException(errorCode.getCode(), message);
        exception.setData(data);
        return exception;
    }

}
